<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\User;
use App\Models\GoodsBrowse;
use App\Jobs\SaveGoodsBrowseJobs;



class SaveGoodsBrowseCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'szsmkj:SaveGoodsBrowseCommand';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '生成用户商品浏览量';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $goodsBrowse = GoodsBrowse::whereDate('created_at' , now())->first();
        $users = User::query()->get();

        if ($goodsBrowse){
            foreach ($users as $v) {
                dispatch(new SaveGoodsBrowseJobs($v , 0));
            }
        }else{
            exec('php artisan szsmkj:GenerateUserGoodsBrowse > ./dev 2>&1');
        }
        //
    }
}
